# encoding: utf-8 -*-
from common.driver import GlobalDriver
from common.file_load import load_yaml_file
from common.process_data import GetData


class BasePage:
    def __init__(self):
        self.driver = GlobalDriver.globalDriver
        if load_yaml_file('/config/config.yml')['env'] == 'test':
            self.manager_base_url = 'https://im.ygsoft.com/testing/ecs/mapp/manage/pc/financialHome/admin.html#'
            self.user_base_url = 'https://im.ygsoft.com/testing/ecs/mapp/manage/pc/financialHome/index.html#'
        if load_yaml_file('/config/config.yml')['env'] == 'release':
            self.manager_base_url = 'https://im.ygsoft.com/release/ecs/mapp/manage/pc/financialHome/admin.html#'
            self.user_base_url = 'https://im.ygsoft.com/release/ecs/mapp/manage/pc/financialHome/index.html#'
        self.page_eles = None
        self.getdata = GetData()

    def click(self, ele_name):
        ele_info = self.page_eles[ele_name]
        self.driver.click(ele_info)

    def send_keys(self, ele_name, text):
        ele_info = self.page_eles[ele_name]
        self.driver.send_keys(ele_info, text)

    def get(self, url):
        self.driver.get(url)

    def get_text(self, ele_name):
        ele_info = self.page_eles[ele_name]
        return self.driver.get_text(ele_info)

    def find_element(self, ele_name):
        ele_info = self.page_eles[ele_name]
        if self.driver.find_element(ele_info):
            return True
        else:
            return False

    def get_element_click(self, ele_name):
        self.driver.get_element_click(ele_name)

    # def upload_enclosure(self, ele_info, file_addr):
    #     self.driver.click(ele_info)
    #     time.sleep(2)
    #     # 指定图片的路径
    #     send_keys(file_addr)
    #     # 敲回车键
    #     send_keys("{VK_RETURN}")


class BaseManagerPage(BasePage):
    def __init__(self):
        super().__init__()
        self.page_eles = load_yaml_file('/pagefiles/login.yml')[self.__class__.__name__]


class BaseUserPage(BasePage):
    def __init__(self):
        super().__init__()
        self.page_eles = load_yaml_file('/pagefiles/login.yml')[self.__class__.__name__]


class BaseTrainPage(BasePage):
    def __init__(self):
        super().__init__()
        self.page_eles = load_yaml_file('/pagefiles/training.yml')[self.__class__.__name__]


class BaseRegulationPage(BasePage):
    def __init__(self):
        super().__init__()
        self.page_eles = load_yaml_file('/pagefiles/regulation.yml')[self.__class__.__name__]

    # def click(self, ele_name):
    #     ele_info = self.page_eles[ele_name]
    #     self.driver.click(ele_info)
    #
    # def send_keys(self, ele_name, text):
    #     ele_info = self.page_eles[ele_name]
    #     self.driver.send_keys(ele_info, text)


if __name__ == '__main__':
    print(BaseTrainPage().page_eles)
